package com.jdk.learn.juc._07Conditon;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by ricky
 * on 2018/2/1.
 */
public class CycleExecute2 {
    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor executor=
                new ThreadPoolExecutor(2,2,10, TimeUnit.SECONDS,new LinkedBlockingQueue());
        //核心线程数，最大线程数，过期时间，线程队列

        for (int i = 0; i < 20; i++) {
            executor.execute(() -> System.out.print("A"));
            executor.awaitTermination(1, TimeUnit.MILLISECONDS);
            executor.execute(() -> System.out.print("B"));
            executor.awaitTermination(1, TimeUnit.MILLISECONDS);
        }

    }
}
